package com.wy.wait_and_notify;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 美女
 * @date 2022/05/02 15:19
 **/
public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        //创建lock锁
        Lock lock=new ReentrantLock();
         Condition condition = lock.newCondition();
//         condition.await();//等价于sync中wait();
//        condition.signal();
//        condition.signalAll();
        //使用上面三个时，也不能直接使用，得先对lock加锁
        lock.lock();
        try {
            condition.await();
        }finally {
            lock.unlock();
        }
    }
}
